package com.aierkeji.call.b2c.dao.jpa;

import java.util.List;

import javax.transaction.Transactional;

import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import com.aierkeji.call.b2c.dao.BaseJPADao;
import com.aierkeji.call.b2c.dao.jpa.custom.AkjCallApprovalHistroDaoCustom;
import com.aierkeji.call.b2c.entity.AkjCallApprovalHistro;
import com.aierkeji.call.b2c.entity.snap.AkjCallUserSnap;

public interface AkjCallApprovalHistroDao extends BaseJPADao<AkjCallApprovalHistro, String>,AkjCallApprovalHistroDaoCustom{

	
	AkjCallApprovalHistro findById(@Param("id")Long id);
	
	@Query(value = "select t from AkjCallApprovalHistro t where approval_user_id = :approvalUserId")
	AkjCallApprovalHistro findByApprovalUserId(@Param("approvalUserId")AkjCallUserSnap akjCallUserSnap);

	@Query(value = "select t from AkjCallApprovalHistro t where apply_user_id = :applyUserId")
	List<AkjCallApprovalHistro> findByApplyUserId(@Param("applyUserId")AkjCallUserSnap akjCallUserSnap);
	
	@Query(value = "select t from AkjCallApprovalHistro t where apply_user_id = :applyUserId and is_delete = :isDelete")
	List<AkjCallApprovalHistro> findByApplyUserIdAndIsDelete(@Param("applyUserId")AkjCallUserSnap akjCallUserSnap, @Param("isDelete")Boolean isDelete );
	
	
	@Query(value = "select t from AkjCallApprovalHistro t where apply_user_id = :applyUserId and approvalResult is null")
	AkjCallApprovalHistro findByApplyUserIdNoApprovalResult(@Param("applyUserId")AkjCallUserSnap akjCallUserSnap);

    @Transactional
	@Query("delete from AkjCallApprovalHistro where apply_user_id = :applyUserId")
	@Modifying
	int deleteByApplyUserId(@Param("applyUserId")AkjCallUserSnap akjCallUserSnap);
	
    @Transactional
	@Query("delete from AkjCallApprovalHistro where id = :id")
	@Modifying
	void deleteById(@Param("id") Long id);


}
